package fr.upstlse.glre.client.widgets.fields;

import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.TextField;

import fr.upstlse.glre.client.constante.fields.ActualiteConstante;
import fr.upstlse.glre.client.vo.actualite.ActualiteVOGWT;

public class ActualiteFields implements IFields {

	FormPanel formPanel;
	ActualiteVOGWT actualiteVOGWT;
	
	private TextField<String> id;
	private TextField<String> titre;
	private TextField<String> contenu;
	private TextField<String> date;
	private TextField<String> userId;
	
	
	
	
	public ActualiteFields(ActualiteVOGWT pActualiteVOGWT, FormPanel pFormPanel) {
		actualiteVOGWT = pActualiteVOGWT;
		formPanel = pFormPanel;
		
		id = new TextField<String>();
		titre = new TextField<String>();
		contenu = new TextField<String>();
		date = new TextField<String>();
		userId = new TextField<String>();
		
		createFields();
		
		if(actualiteVOGWT != null) {
			setFieldsValues();
		}
	}

	public void createFields() {
		id.setName(ActualiteConstante.ID.getValue());
		id.setVisible(false);
		id.setLabelStyle("display: none");
		formPanel.add(id);
		
		titre.setName(ActualiteConstante.TITRE_NAME.getValue());
		titre.setFieldLabel(ActualiteConstante.TITRE_LABEL.getValue());
		formPanel.add(titre);
		
		contenu.setName(ActualiteConstante.CONTENU_NAME.getValue());
		contenu.setFieldLabel(ActualiteConstante.CONTENU_LABEL.getValue());
		formPanel.add(contenu);
		
		date.setName(ActualiteConstante.DATE.getValue());
		date.setVisible(false);
		date.setLabelStyle("display: none");
		formPanel.add(date);
		
		userId.setName(ActualiteConstante.USERID.getValue());
		userId.setVisible(false);
		userId.setLabelStyle("display: none");
		formPanel.add(userId);

	}

	public void removeFields() {
		// TODO Auto-generated method stub

	}

	public void setFieldsValues() {
		id.setValue(new Long(actualiteVOGWT.getId()).toString());
		titre.setValue(actualiteVOGWT.getTitre());
		contenu.setValue(actualiteVOGWT.getContenu());
		date.setValue(actualiteVOGWT.getDate().toString());
		userId.setValue(new Long(actualiteVOGWT.getUserVOGWT().getId()).toString());
	}

	public FormPanel getFormPanel() {
		return formPanel;
	}

	public void setFormPanel(FormPanel pFormPanel) {
		formPanel = pFormPanel;
	}

	public ActualiteVOGWT getActualiteVOGWT() {
		return actualiteVOGWT;
	}

	public void setActualiteVOGWT(ActualiteVOGWT pActualiteVOGWT) {
		actualiteVOGWT = pActualiteVOGWT;
	}

	public TextField<String> getId() {
		return id;
	}

	public void setId(TextField<String> pId) {
		id = pId;
	}

	public TextField<String> getTitre() {
		return titre;
	}

	public void setTitre(TextField<String> pTitre) {
		titre = pTitre;
	}

	public TextField<String> getContenu() {
		return contenu;
	}

	public void setContenu(TextField<String> pContenu) {
		contenu = pContenu;
	}

	public TextField<String> getDate() {
		return date;
	}

	public void setDate(TextField<String> pDate) {
		date = pDate;
	}

	public TextField<String> getUserId() {
		return userId;
	}

	public void setUserId(TextField<String> pUserId) {
		userId = pUserId;
	}
}
